<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?=form_hidden("ID", $this->input->post("ID"))?>
<?=form_hidden("ENTITY", $this->input->post("ENTITY"))?>

<div class="form-group">
	<?=form_label($this->lang->line("NAME_OF_COURSE"), "maj_name", array("class" => "control-label"))?>
	<?=form_input("maj_name", (isset($getMajor[0]["majName"]) ? $getMajor[0]["majName"] : null), "placeholder=\"".$this->lang->line("NAME_OF_COURSE")."\" class=\"form-control\" id=\"maj_name\"")?>
</div>

<div class="form-group">
	<?=form_label($this->lang->line("PLEASE_CHOOSE_LISTING_INTERVAL"), "maj_name", array("class" => "control-label"))?>
	<div class="row">
		<div class="col-md-3">
			<div class="input-group">
				<?=form_input("maj_list_from_date", (isset($getMajor[0]["majListFromDate"]) ? $getMajor[0]["majListFromDate"] : null), "placeholder=\"mm.dd.yyyy\" class=\"form-control\" id=\"maj_list_from_date\"")?>
				<span class="input-group-addon" style="cursor:pointer"><span onclick="$('input[name=maj_list_from_date]').focus()" class="glyphicon glyphicon-calendar"></span></span>
			</div>
		</div>
		<div class="col-md-1 text-center">
			<p class="form-control-static">-</p>
		</div>
		<div class="col-md-3">
			<div class="input-group">
				<?=form_input("maj_list_till_date", (isset($getMajor[0]["majListTillDate"]) ? $getMajor[0]["majListTillDate"] : null), "placeholder=\"mm.dd.yyyy\" class=\"form-control\" id=\"maj_list_till_date\"")?>
				<span class="input-group-addon" style="cursor:pointer"><span onclick="$('input[name=maj_list_till_date]').focus()" class="glyphicon glyphicon-calendar"></span></span>
			</div>
		</div
	</div>
</div>

<script>
	$(function() {

		var from = $('#maj_list_from_date').datepicker({
			format: 'mm.dd.yyyy'
		}).on('changeDate', function(e) {
			$(this).datepicker('hide');
		}).keydown(function() {
			$this = $(this);
			setTimeout(function () {
				if (!$this.is(':focus')) {
					$this.datepicker("hide");
				}
			}, 250);
		}).data('datepicker');

		var till = $('#maj_list_till_date').datepicker({
			format: 'mm.dd.yyyy'
		}).on('changeDate', function(e) {
			$(this).datepicker('hide');
		}).keydown(function() {
			$this = $(this);
			setTimeout(function () {
				if (!$this.is(':focus')) {
					$this.datepicker("hide");
				}
			}, 250);
		}).data('datepicker');

	});
</script>

<div class="form-group">
	<?=form_label($this->lang->line("INSTITUTE"), "maj_ins_id", array("class" => "control-label"))?>
	<?=form_dropdown("maj_ins_id", $getInstituteList, (isset($getMajor[0]["majInsId"]) ? $getMajor[0]["majInsId"] : null), "id=\"maj_ins_id\" style=\"width: 100%;\"")?>
	<script>
		$(function() {
			$('#maj_ins_id').change(function() {
				$('#acc_id').select2('enable', $(this).val() > 0);
				if(!$(this).val())
					$('#acc_id').select2('val', '');
			});
			$('#maj_ins_id').select2();
		});
	</script>
</div>

<div class="form-group">
	<?=form_label($this->lang->line("ACCOMODATION"), "acc_id", array("class" => "control-label"))?>
	<?=form_input("acc_id[]", isset($getMajor[0]["accList"]) ? $getMajor[0]["accList"] : null, "style=\"width:100%;\" id=\"acc_id\"")?>
	<script>
		$(function() {
			$('#acc_id').select2({
				allowClear: true,
				placeholder: '<?=$this->lang->line("ACCOMODATION")?>',
				minimumInputLength: 0,
				enable: $('#ins_ins_id').val() > 0,
				multiple: true,
				ajax: {
					url: '<?=site_url("admin_lte/get_accomodation")?>',
					cache: false,
					dataType: 'json',
					data: function (term, page) {
						return {
							q: term,
							'insId': $('#maj_ins_id').val()
						};
					},
					results: function (data, page) {
						return {results: data, more: false};
					}
				},
				<? if(isset($getMajor[0]["accList"]) and $getMajor[0]["majInsId"]) { ?>
				initSelection: function(element, callback) {
					$.ajax('<?=site_url("admin_lte/get_accomodation")?>' + $('#maj_ins_id').val(), {
						cache: false,
						dataType: "json"
					}).done(function(data) { callback(data); });
				},
				<? } ?>
				formatSelection: function(a, b, c) {
					if($.isArray(a)) {
						return a[0].text;
					}
					return a.text;
				},
				escapeMarkup: function (m) { return m; }
			});
		});
	</script>
</div>

<div class="form-group">
	<?=form_label($this->lang->line("SUBJECT_AREA_OF_THE_COURSE"), "sch_sub_id", array("class" => "control-label"))?>
	<select id="maj_sub_id" name="maj_sub_id" style="width:100%;">
		<? 
		foreach($getSubjectList as $par) {
			echo	"<optgroup label=\"".$par["subName"]."\">";
			foreach($par["children"] as $child) {
				echo		"<option value=\"".$child["subId"]."\">".$child["subName"]."</option>";
			}
			echo	"</optgroup>";
		}
		?>
	</select>
	<script>
		$(function() {
			$('#maj_sub_id').select2();
		});
	</script>
</div>

<div class="form-group">
	<?=form_label($this->lang->line("TYPE_OF_THE_COURSE"), "maj_prog_type", array("class" => "control-label"))?>
	<?=form_dropdown("maj_prog_type", $szotar["PROGTYPE"], (isset($getMajor[0]["majProgType"]) ? $getMajor[0]["majProgType"] : null), "id=\"maj_prog_type\" style=\"width: 100%;\"")?>
	<script>
		$(function() {
			$('#maj_prog_type').change(function() {
				if(!$(this).val())
					$('#maj_prog_type2').select2('val', '');
			});
			$('#maj_prog_type').select2();
		});
	</script>
</div>

<div class="form-group">
	<?=form_label($this->lang->line("PROGRAM_TYPE"), "maj_prog_type2", array("class" => "control-label"))?>
	<?=form_input("maj_prog_type2", (isset($getMajor[0]["majProgType2"]) ? $getMajor[0]["majProgType2"] : null), "style=\"width:100%;\" id=\"maj_prog_type2\"")?>
	<script>
		$(function() {
			$('#maj_prog_type2').select2({
				allowClear: true,
				placeholder: '<?=$this->lang->line("PROGRAM_TYPE")?>',
				minimumInputLength: 0,
				ajax: {
					url: '<?=site_url("admin_lte/get_szotar/PROGTYPE_2")?>',
					cache: false,
					dataType: 'json',
					data: function (term, page) {
						return {
							q: term,
							'progType': $('#maj_prog_type').val()
						};
					},
					results: function (data, page) {
						return {results: data, more: false};
					}
				},
				initSelection: function(element, callback) {
					var id = $(element).val();
					if (id!=="") {
						$.ajax('<?=site_url("admin_lte/get_szotar/PROGTYPE_2")?>' + $('#maj_ins_id').val(), {
							data: {
								id: id
							},
							cache: false,
							dataType: "json"
						}).done(function(data) { callback(data); });
					}
				},
				formatSelection: function(a, b, c) {
					if($.isArray(a)) {
						return a[0].text;
					}
					return a.text;
				},
				escapeMarkup: function (m) { return m; }
			});
		});
	</script>
</div>

<?=Common::generateForm($getCategoryVal)?>